﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FindLinkForum
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // Properties
        List<ForumItem> _lstResults = new List<ForumItem>();

        // 
        // Get all - add treeview
        private void AddDataToTreeView(string url)
        {
            
                _lstResults = RequestHandle.GetAllLinkForumByWebsite(url);
                if (_lstResults != null)
                {
                    TreeNode tNode = new TreeNode();
                    tNode.Text = "1. " + txtUrl.Text;

                    int countLink = 0;
                    foreach (ForumItem item in _lstResults)
                    {
                        if (item == null)
                            continue;
                        tNode.Nodes.Add((countLink++).ToString() + ". " + item.NameForum + ": ### " + item.LinkForum);
                    }
                    tvResults.Nodes.Add(tNode);
                }
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            if (txtUrl.Text != "")
            {
                AddDataToTreeView(txtUrl.Text);
            }
        }
    }
}
